/*********************************************************************************************
*           Titel: Cdef.h
*          Author: L.Cezner, SV I IP DT DS QE
*        Platform: V850 (NEC-JCP)
*
*   Revision List: (Will be filled by PVCS)
*         Archive: $Log:   \\HBWN304A\DIDB0022\AUS\archives\Software\Systems\AUS\BMW\RTC\inc\Cdef.h-arc  $
* AUS * 
* AUS *    Rev 1.1   May 13 2010 14:00:28   Kapeel.Deo
* AUS * Second round of changes based on testing with existing k26.  This will be used as the initial release to BMW.
* AUS * 
* AUS *    Rev 1.0   Mar 17 2010 16:52:02   Kapeel.Deo
* AUS * Initial revision.
*********************************************************************************************/



#ifndef INC_CDEF_H
#define INC_CDEF_H

/* System-headerfiles */
#include <limits.h>            /* type range definitions                                  */
#include <stddef.h>            /* e.g. NULL, size_t, ptrdiff_t , ...                      */       


/* ___________________________________________________________________________________________
 *                              check general assumptions 
 * 
 * Only "exotic" hardware (e.g. 4bit CPUs) should produce an error here 
 * These checkings were triggered by _ANSI_CHECK_ in VGC version of cdef.h 
 */    
#if CHAR_BIT != 8
#error __FILE__ : not 8 bits per byte. Check <limits.h>
#endif
 
#if USHRT_MAX != 0xFFFF
#error __FILE__ : unsigned short range is not 0 .. 0xFFFF. Check your <limits.h>
#endif

#if ULONG_MAX != 0xFFFFFFFFUL
#error __FILE__ : unsigned long range is not 0 .. 0xFFFFFFFF. Check your <limits.h>
#endif

/* ___________________________________________________________________________________________
 *                             define 9S08 related macros:
 */

/*
*---------------------------- PRAGMA adaption for PEMicro ---------------------------------
*/
#if 0
#define inline  __inline
#define __short                        /* resolved to special keyword __direct for FJ16     */
#define __far                          /* special keyword from FJ16 ?                       */
#define __near                         /* special keyword from FJ16 ?                       */
#endif

/* ___________________________________________________________________________________________
 *                                 Basic data types 
 */ 
#ifndef __cplusplus                    /* use Std ANSI C++ macro to detect C++ compilation  */
  typedef unsigned char        bool;   /* Boolean datatype  (keyword in C++)                */
#endif
  

  typedef unsigned char       uint8;   /* Unsigned 8-bit datatype : 0..255                  */
  typedef unsigned short     uint16;   /* Unsigned 16-bit datatype: 0..65535                */
  typedef unsigned long      uint32;   /* Unsigned 32-bit datatype: 0..4294967296           */
  typedef unsigned long long uint64;

  typedef signed  char         int8;   /* Signed 8-bit datatype   : -128...+127             */
  typedef short               int16;   /* Signed 16-bit datatype  : -32768..+32767          */
  typedef         long        int32;   /* Signed 32-bit datatype  : -2147483648..2147483647 */
  
  typedef uint8          tu8BitByte;   /* tu8BitByte = (logical) byte within bitfield       */
  typedef uint16        tu16BitWord;   /* tu16BitWord = (logical) word within bitfield      */
  typedef uint32       tu32BitDWord;   /* tu32BitDWord = (logical) dword within bitfield    */

  typedef volatile uint8	 vuint8;   /* volatile unsigned */
  typedef volatile uint16	vuint16;   /* volatile unsigned */

  typedef void (*tvFuncPtr) (void);     /* ptr to function expecting void + returning void   */
  typedef bool (*tboFuncPtr)(void);

/* ___________________________________________________________________________________________
 *                               numeric min/max constants 
 *
 * VDO prefers own names for ANSI macros from limits.h
 */
#define UINT8_MAX    UCHAR_MAX       /* Maximum UInt8 value  */
#define UINT16_MAX   USHRT_MAX       /* Maximum UInt16 value */
#define UINT32_MAX   ULONG_MAX       /* Maximum UInt32 value */
#define INT8_MIN     SCHAR_MIN       /* Minimum Int8 value   */
#define INT8_MAX     SCHAR_MAX       /* Maximum Int8 vlaue   */
#define INT16_MIN    SHRT_MIN        /* Minimum Int16 value  */
#define INT16_MAX    SHRT_MAX        /* Maximum Int16 value  */
#define INT32_MIN    LONG_MIN        /* Minimum Int32 value  */
#define INT32_MAX    LONG_MAX        /* Maximum Int32 value  */

/* ___________________________________________________________________________________________
 *                                    bool constants 
 */
#define True    (bool) ( 1 == 1 )    /* Boolean value for True  */
#define False   (bool) ( 1 == 0 )    /* Boolean value for False */

/* ___________________________________________________________________________________________
 *                                integer-type constants 
 */
/* NOTE: Some compilers interprets every constant as "int". Therefore when used as function
 parameter of type "char" or "short", a cast should be used in order to avoid compiler warnings
 */
#define Yes       1                  /* Integer-type value for Yes   */
#define No        0                  /* Integer-type value for No    */
#define On        1                  /* Integer-type value for On    */
#define Off       0                  /* Integer-type value for Off   */
#define Ok        1                  /* Integer-type value for Ok    */
#define NotOk     0                  /* Integer-type value for NotOk */

/* ___________________________________________________________________________________________
 *                                       bit masks 
 */
#define GetBitMaskB(n) (0x01u<<(n))   /* returns const unsigned int - only bit n set to 1 */
 
#define nu8Bit0    ((uint8)      1)                      /* Bitmask for bit 0  */
#define nu8Bit1    ((uint8)      2)                      /* Bitmask for bit 1  */
#define nu8Bit2    ((uint8)      4)                      /* Bitmask for bit 2  */
#define nu8Bit3    ((uint8)      8)                      /* Bitmask for bit 3  */
#define nu8Bit4    ((uint8)     16)                      /* Bitmask for bit 4  */
#define nu8Bit5    ((uint8)     32)                      /* Bitmask for bit 5  */
#define nu8Bit6    ((uint8)     64)                      /* Bitmask for bit 6  */
#define nu8Bit7    ((uint8)    128)                      /* Bitmask for bit 7  */

#define nu16Bit0   ((uint16)     1)                      /* Bitmask for bit 0  */
#define nu16Bit1   ((uint16)     2)                      /* Bitmask for bit 1  */
#define nu16Bit2   ((uint16)     4)                      /* Bitmask for bit 2  */
#define nu16Bit3   ((uint16)     8)                      /* Bitmask for bit 3  */
#define nu16Bit4   ((uint16)    16)                      /* Bitmask for bit 4  */
#define nu16Bit5   ((uint16)    32)                      /* Bitmask for bit 5  */
#define nu16Bit6   ((uint16)    64)                      /* Bitmask for bit 6  */
#define nu16Bit7   ((uint16)   128)                      /* Bitmask for bit 7  */
#define nu16Bit8   ((uint16)   256)                      /* Bitmask for bit 8  */
#define nu16Bit9   ((uint16)   512)                      /* Bitmask for bit 9  */
#define nu16Bit10  ((uint16)  1024)                      /* Bitmask for bit 10 */
#define nu16Bit11  ((uint16)  2048)                      /* Bitmask for bit 11 */
#define nu16Bit12  ((uint16)  4096)                      /* Bitmask for bit 12 */
#define nu16Bit13  ((uint16)  8192)                      /* Bitmask for bit 13 */
#define nu16Bit14  ((uint16) 16384)                      /* Bitmask for bit 14 */
#define nu16Bit15  ((uint16) 32768)                      /* Bitmask for bit 15 */

#define nu32Bit0   ((unsigned long) 0x00000001)          /* Bitmask for bit 0  */
#define nu32Bit1   ((unsigned long) 0x00000002)          /* Bitmask for bit 1  */
#define nu32Bit2   ((unsigned long) 0x00000004)          /* Bitmask for bit 2  */
#define nu32Bit3   ((unsigned long) 0x00000008)          /* Bitmask for bit 3  */
#define nu32Bit4   ((unsigned long) 0x00000010)          /* Bitmask for bit 4  */
#define nu32Bit5   ((unsigned long) 0x00000020)          /* Bitmask for bit 5  */
#define nu32Bit6   ((unsigned long) 0x00000040)          /* Bitmask for bit 6  */
#define nu32Bit7   ((unsigned long) 0x00000080)          /* Bitmask for bit 7  */
#define nu32Bit8   ((unsigned long) 0x00000100)          /* Bitmask for bit 8  */
#define nu32Bit9   ((unsigned long) 0x00000200)          /* Bitmask for bit 9  */
#define nu32Bit10  ((unsigned long) 0x00000400)          /* Bitmask for bit 10 */
#define nu32Bit11  ((unsigned long) 0x00000800)          /* Bitmask for bit 11 */
#define nu32Bit12  ((unsigned long) 0x00001000)          /* Bitmask for bit 12 */
#define nu32Bit13  ((unsigned long) 0x00002000)          /* Bitmask for bit 13 */
#define nu32Bit14  ((unsigned long) 0x00004000)          /* Bitmask for bit 14 */
#define nu32Bit15  ((unsigned long) 0x00008000)          /* Bitmask for bit 15 */
#define nu32Bit16  ((unsigned long) 0x00010000)          /* Bitmask for bit 16 */
#define nu32Bit17  ((unsigned long) 0x00020000)          /* Bitmask for bit 17 */
#define nu32Bit18  ((unsigned long) 0x00040000)          /* Bitmask for bit 18 */
#define nu32Bit19  ((unsigned long) 0x00080000)          /* Bitmask for bit 19 */
#define nu32Bit20  ((unsigned long) 0x00100000)          /* Bitmask for bit 20 */
#define nu32Bit21  ((unsigned long) 0x00200000)          /* Bitmask for bit 21 */
#define nu32Bit22  ((unsigned long) 0x00400000)          /* Bitmask for bit 22 */
#define nu32Bit23  ((unsigned long) 0x00800000)          /* Bitmask for bit 23 */
#define nu32Bit24  ((unsigned long) 0x01000000)          /* Bitmask for bit 24 */
#define nu32Bit25  ((unsigned long) 0x02000000)          /* Bitmask for bit 25 */
#define nu32Bit26  ((unsigned long) 0x04000000)          /* Bitmask for bit 26 */
#define nu32Bit27  ((unsigned long) 0x08000000)          /* Bitmask for bit 27 */
#define nu32Bit28  ((unsigned long) 0x10000000)          /* Bitmask for bit 28 */
#define nu32Bit29  ((unsigned long) 0x20000000)          /* Bitmask for bit 29 */
#define nu32Bit30  ((unsigned long) 0x40000000)          /* Bitmask for bit 30 */
#define nu32Bit31  ((unsigned long) 0x80000000)          /* Bitmask for bit 31 */

/* ___________________________________________________________________________________________
 *                                       converters 
 */
/*
 * Description       : Converts the binary Expression i into a numeric constant. 
 *                     Example:
 *                                nBinUInt8(11001001) -> (0xC9)
 * Parameter:
 *    i                 Binary coded number . Up to 8 digits (0 or 1) are allowed
 */
#define nBinUInt8(i)  ((0x80&(0x0##i##l>>21))|(0x40&(0x0##i##l>>18))    \
                      |(0x20&(0x0##i##l>>15))|(0x10&(0x0##i##l>>12))    \
                      |(0x08&(0x0##i##l>> 9))|(0x04&(0x0##i##l>> 6))    \
                      |(0x02&(0x0##i##l>> 3))|(0x01&(0x0##i##l    )))
 
#define bBinUInt8(i)        ((uint8)nBinUInt8(i))                       /* returns uint8  */

#define nBinUInt16(i,j)     ((nBinUInt8(i)<<8)|nBinUInt8(j))            /* returns uint16 */

#define wBinUInt16(i,j,k,l) ((uint16)nBinUInt16(i,j)<<16|(uint16)nBinUInt16(k,l)) 
                                                                          /* returns uint32 */

/* ___________________________________________________________________________________________
 *                             bit and byte access types
 */
/* -------------------------------------------------------------------------------------------
*  Description      : Bitfield data type with 8 bits. The following bitfield depends on
*                     the compiler and machine! The defined structure has to be redefined
*                     for other compilers, so that the following conditions are correct:
*                     bit8 bibBitF8
*                     bibBitF8.B == ( bibBitF8.F._7 * 2^7 ) + 
*                                   ( bibBitF8.F._6 * 2^6 ) + ...
*                                   ( bibBitF8.F._0 * 2^0 ) 
*/
 typedef union
   {
   uint8 B;                      /* Byte access identifier */
   struct
      {
      uint8 _0 : 1;              /* least significant bit. range = 0..1 */
      uint8 _1 : 1;
      uint8 _2 : 1;
      uint8 _3 : 1;
      uint8 _4 : 1;
      uint8 _5 : 1;
      uint8 _6 : 1;
      uint8 _7 : 1;              /* most significant bit. range = 0..1 */
      } F;                       /* Flag access identifier */
   } bit8;

/* -------------------------------------------------------------------------------------------
 * Description         : Bitfield data type with 16 bits
 *                       The following bitfield depends on the compiler
 *                       and machine! The defined structure has to be
 *                       redefined for other compilers, so that the following
 *                       conditions are correct:
 *                       bit16 biwBitF16
 *                       biwBitF16.W    == ( biwBitF16.B._1  * 2^8  ) +
 *                                         ( biwBitF16.B._0  * 2^0  )
 *                       biwBitF16.W    == ( biwBitF16.F._15 * 2^15 ) +
 *                                         ( biwBitF16.F._14 * 2^14 ) + ...
 *                                         ( biwBitF16.F._0  * 2^0  )
 */
 typedef union
   {
   uint16 W;                    /* Word access identifier */
   struct
      {
      uint8 _1;                 /* High byte (Bits 8 to 15) . Range  0..255     */   
      uint8 _0;                 /*  Low byte (Bits 0 to  7) . Range  0..255     */
      } B;                      /* Byte access identifier                       */
   struct
      {
      uint16 _8 : 1;            /* least significant bit (byte 1). Range = 0..1 */
      uint16 _9 : 1;
      uint16 _10: 1;
      uint16 _11: 1;
      uint16 _12: 1;
      uint16 _13: 1;
      uint16 _14: 1;
      uint16 _15: 1;            /*  most significant bit (byte 1). Range = 0..1 */

      uint16 _0 : 1;            /* least significant bit (byte 0). Range = 0..1 */
      uint16 _1 : 1;
      uint16 _2 : 1;
      uint16 _3 : 1;
      uint16 _4 : 1;
      uint16 _5 : 1;
      uint16 _6 : 1;
      uint16 _7 : 1;            /*  most significant bit (byte 0). Range = 0..1 */
      } F;                      /* Flag access identifier */
   } bit16;

/* -------------------------------------------------------------------------------------------
 * Description         : Word data type with single accessable bytes
 *                       The following bitfield depends on the compiler
 *                       and machine! The defined structure has to be
 *                       redefined for other compilers, so that the following
 *                       conditions are correct:
 *                       tunU16Rec unWRec
 *                       unWRec.u16W == ( unWRec.stB.u8B1 * 2^8 ) +
 *                                      ( unWRec.stB.u8B0 * 2^0 )
 */
 typedef union
   {
   uint16 u16W;                        /* Word access identifier */

   struct
      {
      uint8   u8B1;                    /* High byte (Bits 8 to 15) . Range  0..255 */
      uint8   u8B0;                    /*  Low byte (Bits 0 to  7) . Range  0..255 */
      } stB;                           /* Byte access identifier */
   } tunU16Rec;

/* -------------------------------------------------------------------------------------------
 * Description         : Dword data type with single accessable words and bytes
 *                       The following bitfield depends on the compiler
 *                       and machine! The defined structure has to be
 *                       redefined for other compilers, so that the following
 *                       conditions are correct:
 *                       tunU32Rec unDWRec
 *                       unDWRec.stW.u16W0 == ( unDWRec.stB.u8B1  * 2^8  ) +
 *                                            ( unDWRec.stB.u8B0  * 2^0  )
 *                       unDWRec.stW.u16W1 == ( unDWRec.stB.u8B3  * 2^8  ) +
 *                                            ( unDWRec.stB.u8B2  * 2^0  )
 *                       unDWRec.u32DW     == ( unDWRec.stW.u16W1 * 2^16 ) +
 *                                            ( unDWRec.stW.u16W0 * 2^0  )
 */
 typedef union
   {
   uint32 u32DW;                       /* Dword access identifier */

   struct
      {
      uint16   u16W1;                  /* High word  Range = 0 .. 65535 */
      uint16   u16W0;                  /*  Low word. Range = 0 .. 65535 */
      } stW;                           /* Word access identifier */

   struct
      {
      uint8   u8B3;                    /* High  byte of high  word = most significant byte  */
      uint8   u8B2;                    /*  Low byte of high  word                           */
      uint8   u8B1;                    /* High byte of low word                             */
      uint8   u8B0;                    /*  Low byte of low  word   = least significant byte */
      } stB;                           /* Byte access identifier */
   } tunU32Rec;

/* ___________________________________________________________________________________________
 * ___________________________________________________________________________________________
 *                      keep compatibility with existing sources
 */
#ifndef  TYPEDEFS_SMK_3_00               /* switch for excluding old prototypes             */

typedef         uint8        byte;     /* Unsigned 8-bit datatype : 0..255                */
typedef        uint16        word;     /* Unsigned 16-bit datatype: 0..65535              */
typedef        uint32       dword;     /* Unsigned 32-bit datatype: 0..4294967296         */
typedef          bit8        bitb;     /* Bitfield data type with  8 bits                 */
typedef         bit16   tBitField;     /* Bitfield data type with 16 bits                 */

#define BYTE_MAX        UINT8_MAX      /* Maximum Byte value  */
#define WORD_MAX       UINT16_MAX      /* Maximum Word value  */
#define DWORD_MAX      UINT32_MAX      /* Maximum Dword value */

#define mediumconst const              /* resolved to special const __far    for FJ16     */

#define nbBit0          nu8Bit0        /* Bitmask for bit 0  */
#define nbBit1          nu8Bit1        /* Bitmask for bit 1  */
#define nbBit2          nu8Bit2        /* Bitmask for bit 2  */
#define nbBit3          nu8Bit3        /* Bitmask for bit 3  */
#define nbBit4          nu8Bit4        /* Bitmask for bit 4  */
#define nbBit5          nu8Bit5        /* Bitmask for bit 5  */
#define nbBit6          nu8Bit6        /* Bitmask for bit 6  */
#define nbBit7          nu8Bit7        /* Bitmask for bit 7  */
                                
#define nwBit0         nu16Bit0        /* Bitmask for bit 0  */
#define nwBit1         nu16Bit1        /* Bitmask for bit 1  */
#define nwBit2         nu16Bit2        /* Bitmask for bit 2  */
#define nwBit3         nu16Bit3        /* Bitmask for bit 3  */
#define nwBit4         nu16Bit4        /* Bitmask for bit 4  */
#define nwBit5         nu16Bit5        /* Bitmask for bit 5  */
#define nwBit6         nu16Bit6        /* Bitmask for bit 6  */
#define nwBit7         nu16Bit7        /* Bitmask for bit 7  */
#define nwBit8         nu16Bit8        /* Bitmask for bit 8  */
#define nwBit9         nu16Bit9        /* Bitmask for bit 9  */
#define nwBit10        nu16Bit10       /* Bitmask for bit 10 */
#define nwBit11        nu16Bit11       /* Bitmask for bit 11 */
#define nwBit12        nu16Bit12       /* Bitmask for bit 12 */
#define nwBit13        nu16Bit13       /* Bitmask for bit 13 */
#define nwBit14        nu16Bit14       /* Bitmask for bit 14 */
#define nwBit15        nu16Bit15       /* Bitmask for bit 15 */

#define dwBit0         nu32Bit0        /* Bitmask for bit 0  */
#define dwBit1         nu32Bit1        /* Bitmask for bit 1  */
#define dwBit2         nu32Bit2        /* Bitmask for bit 2  */
#define dwBit3         nu32Bit3        /* Bitmask for bit 3  */
#define dwBit4         nu32Bit4        /* Bitmask for bit 4  */
#define dwBit5         nu32Bit5        /* Bitmask for bit 5  */
#define dwBit6         nu32Bit6        /* Bitmask for bit 6  */
#define dwBit7         nu32Bit7        /* Bitmask for bit 7  */
#define dwBit8         nu32Bit8        /* Bitmask for bit 8  */
#define dwBit9         nu32Bit9        /* Bitmask for bit 9  */
#define dwBit10        nu32Bit10       /* Bitmask for bit 10 */
#define dwBit11        nu32Bit11       /* Bitmask for bit 11 */
#define dwBit12        nu32Bit12       /* Bitmask for bit 12 */
#define dwBit13        nu32Bit13       /* Bitmask for bit 13 */
#define dwBit14        nu32Bit14       /* Bitmask for bit 14 */
#define dwBit15        nu32Bit15       /* Bitmask for bit 15 */
#define dwBit16        nu32Bit16       /* Bitmask for bit 16 */
#define dwBit17        nu32Bit17       /* Bitmask for bit 17 */
#define dwBit18        nu32Bit18       /* Bitmask for bit 18 */
#define dwBit19        nu32Bit19       /* Bitmask for bit 19 */
#define dwBit20        nu32Bit20       /* Bitmask for bit 20 */
#define dwBit21        nu32Bit21       /* Bitmask for bit 21 */
#define dwBit22        nu32Bit22       /* Bitmask for bit 22 */
#define dwBit23        nu32Bit23       /* Bitmask for bit 23 */
#define dwBit24        nu32Bit24       /* Bitmask for bit 24 */
#define dwBit25        nu32Bit25       /* Bitmask for bit 25 */
#define dwBit26        nu32Bit26       /* Bitmask for bit 26 */
#define dwBit27        nu32Bit27       /* Bitmask for bit 27 */
#define dwBit28        nu32Bit28       /* Bitmask for bit 28 */
#define dwBit29        nu32Bit29       /* Bitmask for bit 29 */
#define dwBit30        nu32Bit30       /* Bitmask for bit 30 */
#define dwBit31        nu32Bit31       /* Bitmask for bit 31 */

#define nBinByte(i)    (nBinUInt8(i))
#define bBinByte(i)    (bBinUInt8(i))         /* returns byte  */
#define nBinWord(i,j)  (nBinUInt16(i,j))      /* returns word  */ 
/*  #define wBinWord(i,j)  (wBinUInt16(i,j)) */ /* returns dword - NOT USED, WRONG RESULT !!*/

typedef tu8BitByte       tbBitByte;  /* tbBitByte = (logical) byte within bitfield  */
typedef tu16BitWord      twBitWord;  /* tbBitWord = (logical) word within bitfield  */
typedef tu32BitDWord   tdwBitDWord;  /* tbBitWord = (logical) dword within bitfield */

typedef tunU16Rec    tunWordRec;  /* Word data type with single accessable bytes          */
typedef tunU32Rec   tunDwordRec;  /* DWord data type with single accessable words & bytes */
 
#define    wW        u16W            /* Word access identifier */
#define    dwD      u32DW            /* Dword access identifier */
#define    wW0      u16W0            /*  Low word. Range = 0 .. 65535 */
#define    wW1      u16W1            /* High word. Range = 0 .. 65535 */
#define    bB0       u8B0            /*  Low byte of low  word   = least significant byte */
#define    bB1       u8B1            /* High byte of low word                             */
#define    bB2       u8B2            /*  Low byte of high  word                           */
#define    bB3       u8B3            /* High  byte of high  word = most significant byte  */

/* ---------------------------------------------------------------------------------------- */
#endif        /* end of  --->   #ifndef TYPEDEFS_SMK_3_00  (line 422)                       */


/* ---------------------------------------------------------------------------------------- */

#ifdef _ANSI_CHECK_
#pragma PRQA_MESSAGES_ON 0841,3410,3413,3428,3429
#endif


#endif        /* end of  --->   #ifndef INC_CDEF_H         (line  34)                       */



/*====================================== END OF FILE =======================================*/

